import { STORAGE_TOKEN_KEY } from '@/types/meta';
import { App } from 'vue';

import { jwtDecode, JwtPayload } from 'jwt-decode';

const authDirective = (app: App) => {
	app.directive('v-auth', {
		created: (el, binding) => {
			debugger;
			const token = localStorage.getItem(STORAGE_TOKEN_KEY);
			const result = jwtDecode<JwtPayload>(token + '')['_doc'];
			if (result['role'] !== binding.value) {
				el.remove();
			}
		},
	});
};

export default authDirective;
